// pages/pettest/pettest.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    agesex_status: false,
    agesex:null,
    lian_status: true,
    lian: null,
    address_status:true,
    address:null,
    star_status:true,
    star:null,
    fang_status: true,
    fang: null,
    money_status:true,
    money:null,
    cai_status:true,
    cai:null,
    yang_status:true,
    yang: null,
    tong_status: true,
    tong: null,
    submit_status: true,
    topname: '宠物领养小站',
    prepage: 1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  agesex: function (res) {
    var agesex=res.currentTarget.dataset.index;
    this.setData({ agesex: agesex});
    this.setData({ agesex_status: true })
    this.setData({ lian_status: false })
  },
  lian: function (res) {
    var lian = res.currentTarget.dataset.index;
    this.setData({ lian: lian });
    this.setData({ lian_status: true })
    this.setData({ address_status: false })
  },
  address: function (res){
    var address = res.currentTarget.dataset.index;
    this.setData({ address: address });
    this.setData({ address_status: true });
    this.setData({ fang_status: false })
  },
  fang: function (res) {
    var fang = res.currentTarget.dataset.index;
    this.setData({ fang: fang });
    this.setData({ fang_status: true });
    this.setData({ star_status: false })
  },
  starselect: function (res){
    var star = res.currentTarget.dataset.index;
    this.setData({ star: star });
    this.setData({ star_status: true });
    this.setData({ money_status: false })
  },
  money: function (res) {
    var money = res.currentTarget.dataset.index;
    this.setData({ money: money });
    this.setData({ money_status: true });
    this.setData({ cai_status: false })
  },
  cai: function (res) {
    var cai = res.currentTarget.dataset.index;
    this.setData({ cai: cai });
    this.setData({ cai_status: true });
    this.setData({ yang_status: false })
  },
  yang: function (res) {
    var yang = res.currentTarget.dataset.index;
    this.setData({ yang: yang });
    this.setData({ yang_status: true });
    this.setData({ tong_status: false });
  },
  tong: function (res) {
    var tong = res.currentTarget.dataset.index;
    this.setData({ tong: tong });
    this.setData({ tong_status: true });
    this.setData({ submit_status: false });
  },
  submitinfo:function(){
    var agesex=  this.data.agesex
    var lian = this.data.lian
    var address = this.data.address
    var star = this.data.star
    var money = this.data.money
    var cai = this.data.cai
    var yang = this.data.yang
    var tong = this.data.tong
    var fang = this.data.fang
    // console.log(agesex);
    // console.log(lian);
    // console.log(address);
    // console.log(star);
    // console.log(money);
    // console.log(cai);
    // console.log(yang);
    // console.log(tong);
    // console.log(fang);

    wx.request({
      url: 'https://www.cwlyz.com/wx/Pettest/index',
      data: {
         agesex  : agesex,
         lian    : lian,
         address : address,
         star    : star,
         money   : money,
         cai     : cai,
         yang    : yang,
         tong    : tong,
         fang    : fang
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        console.log(res);
        wx.navigateTo({
          url: '../pettestview/pettestview?descriptnew=' + res.data.descriptnew + '&scoreall=' + res.data.scoreall, 
               success:function() { }     
  })
      }
    })
  },
  onShareAppMessage: function (res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: '【养宠测评】您真的适合养宠物吗？',
    }

  }
})